home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / files.swg / 0082_Text File Reading Unit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-22  |  3.9 KB  |  167 lines

  1. Unit WGTFile; {TextFile Reader for CRLF or LF TEXT FILES!}
  2.               {eventually this unit will be a decendant of WGBFILE!}
  3.  
  4. {$I WGDEFINE.INC}  { SEE WGFFIND.PAS for this include }
  5.  
  6. Interface
  7.  
  8. Uses
  9.    WGBFile,
  10. {$IFDEF WINDOWS}
  11.    WinDos;
  12. {$ELSE}
  13.    Dos;
  14. {$ENDIF}
  15.  
  16. Type
  17.    TFile = Object
  18.       Decendant:FFileObj; {short cut for now!}
  19.       StringFound:Boolean;
  20.       MyIOResult:Word;
  21.       Constructor Init(BSize:Word);
  22.       Destructor Done;
  23.       Procedure Open(FilePath:String); Virtual;
  24.       Procedure CloseFile; Virtual;
  25. {      Function  EraseFile; Virtual;}
  26.       Function  GetString:String;             {Get CRLF string from file}
  27.       Function  GetUString:String;            {Get LF delimited string}
  28.       Function  Found:Boolean;                {Was a string found}
  29.       Function  SeekFile(SeekPos:LongInt):Boolean; {Seek to position}
  30.       Function  FilePos:LongInt;              {Get text file position}
  31.       Function  RawSize:LongInt;              {Get text file position}
  32.    End;
  33.  
  34. Implementation
  35.  
  36. Constructor TFile.Init(BSize:Word);
  37. Begin
  38.    Decendant.Init(BSize);
  39.    If Decendant.MyIOResult<>0 then Fail;
  40.    MyIOResult:=0;
  41.    StringFound:=False;
  42. End;
  43.  
  44. Destructor TFile.Done;
  45. Begin
  46.    If Decendant.IsOpen then Decendant.CloseFile;
  47.    Decendant.Done;
  48.    StringFound:=False;
  49. End;
  50.  
  51. Procedure TFile.Open(FilePath:String);
  52. Begin
  53.    Decendant.Open(FilePath,fmReadOnly+fmDenyNone);
  54.    MyIOResult:=Decendant.MyIOResult;
  55. End;
  56.  
  57. Procedure TFile.CloseFile;
  58. Begin
  59.    Decendant.Closefile;
  60.    MyIOResult:=Decendant.MyIOResult;
  61. End;
  62.  
  63. Function  TFile.GetString:String;
  64. Var
  65.    TempStr:String;
  66.    GDone:Boolean;
  67.    Ch:Char;
  68.    NRead:Word;
  69.  
  70. Begin
  71.    TempStr:='';
  72.    StringFound:=False;
  73.    If Decendant.FilePos>=Decendant.RawSize then GDone:=True
  74.    Else GDone:=False;
  75.    While Not GDone Do Begin
  76.       Decendant.BlkRead(Ch,1,NRead);
  77.       MyIOResult:=Decendant.MYIOResult;
  78.       If (MYIOResult<>0) or (NRead<>1) then Ch:=#0;
  79.       Case Ch Of
  80.  #0:If Decendant.FilePos>=Decendant.RawSize Then GDone:=True
  81.        Else Begin
  82.        Inc(TempStr[0]);
  83.        TempStr[Ord(TempStr[0])]:=Ch;
  84.        StringFound:=True;
  85.        If Length(TempStr)=255 Then GDone:=True;
  86.     End;
  87.  #10:;
  88.  #26:;
  89.  #13: Begin
  90.       GDone:=True;
  91.       StringFound:=True;
  92.       End;
  93.       Else Begin
  94.     Inc(TempStr[0]);
  95.     TempStr[Ord(TempStr[0])]:=Ch;
  96.     StringFound:=True;
  97.     If Length(TempStr)=255 Then GDone:=True;
  98.       End;
  99.       End; {case}
  100.    End;
  101.    GetString:=TempStr;
  102. End;
  103.  
  104. Function  TFile.GetUString:String;
  105. Var
  106.    TempStr:String;
  107.    GDone:Boolean;
  108.    Ch:Char;
  109.    NRead:Word;
  110.  
  111. Begin
  112.    TempStr:='';
  113.    StringFound:=False;
  114.    If Decendant.FilePos>=Decendant.RawSize then GDone:=True
  115.    Else GDone:=False;
  116.    While Not GDone Do Begin
  117.       Decendant.BlkRead(Ch,1,NRead);
  118.       MyIOResult:=Decendant.MYIOResult;
  119.       If (MYIOResult<>0) or (NRead<>1) then Ch:=#0;
  120.       Case Ch Of
  121.       #0:If Decendant.FilePos>=Decendant.RawSize Then GDone:=True
  122.   Else Begin
  123.      Inc(TempStr[0]);
  124.      TempStr[Ord(TempStr[0])]:=Ch;
  125.      StringFound:=True;
  126.      If Length(TempStr)=255 Then GDone:=True;
  127.   End;
  128.       #13:;
  129.       #26:;
  130.       #10:Begin
  131.         GDone:=True;
  132.         StringFound:=True;
  133.         End;
  134.       Else Begin
  135.     Inc(TempStr[0]);
  136.     TempStr[Ord(TempStr[0])]:=Ch;
  137.     StringFound:=True;
  138.     If Length(TempStr)=255 Then GDone:=True;
  139.       End;
  140.       End; {case}
  141.    End;
  142.    GetUString:=TempStr;
  143. End;
  144.  
  145. Function  TFile.Found:Boolean;
  146. Begin
  147.    Found:=StringFound;
  148. End;
  149.  
  150. Function  TFile.SeekFile(SeekPos:LongInt):Boolean; {Seek to position}
  151. Begin
  152.    Decendant.SeekFile(SeekPos);
  153.    MyIOResult:=Decendant.MyIOResult;
  154. End;
  155.  
  156. Function  TFile.FilePos:LongInt;              {Get text file position}
  157. Begin
  158.    FilePos:=Decendant.FilePos;
  159. End;
  160.  
  161. Function  TFile.RawSize:LongInt;              {Get text file position}
  162. Begin
  163.    RawSize:=Decendant.RawSize;
  164. End;
  165.  
  166. End.
  167.